// pages/user/account/account.js
import {$wuxDialog} from '../../../wux-components/index'
const config = getApp().globalData.config
const T = getApp().globalData.T
let token = ''

Page({

  /**
   * 页面的初始数据
   */
  data: {
    userIndex: -1,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    token = getApp().globalData.token;
    this.getDetail();
  },

  getDetail() {
    T.req({
      loadTitle: '加载中...',
      url: config.api + 'user/' + getApp().globalData.userInfo.companyId + '/list',
      method: 'GET',
      data: {
        token: token
      },
      success: (res) => {
        console.log(res.list)
        this.setData({
          list: res.list
        })
      }
    })
  },

  onOpen(e) {
    const id = e.currentTarget.dataset.id;
    const checked = e.currentTarget.dataset.checked;
    if (checked != 1) {
      return ;
    }
    $wuxDialog().confirm({
      resetOnClose: true,
      closable: true,
      title: '提示',
      content: '确认将超管权限移交给该账号吗?',
      onConfirm: () => {
        this.onMovePower(id);
      },
      onCancel(e) {

      },
    })
  },

  onMovePower(id) {
    let _param = {
      token: token,
      type: 2,
      checkedHrId: id
    }
    console.log(_param);
    T.req({
      loadTitle: '请求中...',
      url: config.api + 'user/checked?' + T.param(_param),
      method: 'PUT',
      success: (res) => {
        T.toast({
          id: '#toast',
          text: '成功移交',
          success: () => {
            wx.reLaunch({
              url: '/pages/login/index'
            })
          }
        });
      }
    })
  },

  onOperation(e) {
    let status = e.currentTarget.dataset.status;
    let id = e.currentTarget.dataset.id;
    if (status == 0) {
      wx.navigateTo({
        url: './audit/audit?id=' + id,
      })
    }
  },

  onShareAppMessage: function() {
    let param = {
      userId: getApp().globalData.userId,
      userType: 1
    }
    return {
      title:'邀请同事注册',
      path:'/pages/login/index?' + T.param(param),
      imageUrl:'/resource/image/share_bg.png'
    }
  }
})